<template lang="html">
  <div class="goodsdetails">
    <Header :HeaderTitle="header_title"></Header>
    <!-- 地址 -->
    <Address :address="address"></Address>
    <div class="goodsdetails_main">
      <h2>商品升级</h2>
      <GoodsName :goodsname="goods"></GoodsName>
    </div>
    <subtotal :num="goods"></subtotal>
    <div class="payment_box">
      <ul class="payment_main">
        <li class="payment_num">支付:{{zhongji}}元运费</li>
        <li class="payment_pay" @click="putonggoodsbuy()">立即兑换</li>
      </ul>
    </div>
  </div>
</template>

<script type="text/javascript">
  import Header from "../header/header.vue";
  import address from "./address.vue";
  import GoodsName from "./goodsname.vue";
  import subtotal from "./subtotal.vue";
export default {
  name: 'cuxiao',
  data(){
    return{
      header_title:{url:"/",title:"确认订单"},
      address:{},
      goods:{},
      numer:1,
      cur_id:"",
      sign:"",
      goodsid:'',
      zhongji:0
    }
  },
  created:function() {
    let cur_id = sessionStorage.getItem("cur_id"),
    sign = sessionStorage.getItem("sign"),
    routerParams = this.$route.query.id,
    conent = this;
    let _url = "index.php?g=app&m=shopping&a=default_address_and_one_goods_post";
    conent.cur_id = cur_id;
    conent.sign = sign;
    conent.goodsid = routerParams;
    let _addressdata = {
      id:routerParams,
      cur_id:conent.cur_id,
      sign:conent.sign,
      type:"jifen"
    }
    conent.$http.post(_url,_addressdata).then(function(data){
        if(data.data.status== "1"){
          conent.goods =data.data.data.goods_info;
          conent.goods.price =0;
          conent.goods.numer = conent.$route.query.numer;
          conent.goods.Total = conent.goods.price*conent.goods.numer;
          conent.zhongji = parseInt(conent.goods.freight);
          conent.address = data.data.data.default_address;
        }else {
          
        }
    },function(response){});
  },
   methods:{
    putonggoodsbuy:function(){
      let _url = '/index.php?g=app&m=shopping&a=jifengoods_buy_post',
      qs = require('querystring'),
      conent = this,
      _data={
        cur_id:conent.cur_id,
        sign:conent.sign,
        num:conent.goods.numer,
        id:conent.goodsid,
        name:conent.address.name,
        mobile:conent.address.mobile,
        address:conent.address.sheng+conent.address.shi+conent.address.qu+conent.address.address,
      }
      conent.$http.post(_url,_data).then(function(data){
          if(data.data.status== "1"){
            conent.$router.push({ path: '/orderform', params: { userId: "wise" }})
          }else {
            conent.$toast(data.data.info);
            if(data.data.info =="登录过期，请重新登录"){
              sessionStorage.clear();
              top.location = "index.html";
            }
          }
      },function(response){
          conent.$toast(response);
      })
    }
  },
  components:{
    'Header':Header,
     'Address':address,
     'GoodsName':GoodsName,
     'subtotal':subtotal
  }
}
</script>

<style scoped lang="less">
@import '../../../assets/less/index.less';
.goodsdetails{
  width: 100vw;
  .goodsdetails_main{
    border-top: solid 0.5vw @color8;
    text-align: left;
    h2{
      height: 10vw;
      line-height: 10vw;
      font-size: @h1_font_size;
      width: @width;
      margin: 0 auto;
    }
  }
  .payment_box{
    width: 100vw;
    height: 15vw;
    line-height: 15vw;
    font-size: @h2_font_size;
    border-bottom: solid 1px @color8;
    border-top: solid 1px @color8;
    position: fixed;
    bottom: 0;
    left: 0;
    .payment_main{
      width: 100%;
      height: 100%;
      overflow: hidden;
      zoom:1;
      .payment_num{
        float: left;
        width: 66.666%;
      }
      .payment_pay{
        float: right;
        width: 33.333%;
        background-color: @color;
        color: @color1;
      }
    }
  }
}
</style>